//
//  WDGrabOrdersPersonInfoLabelView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/14.
//

#import "WDGrabOrdersPersonInfoLabelView.h"

@interface WDGrabOrdersPersonInfoLabelView ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *thanImgView;
@property (nonatomic, strong) UILabel *valueLabel;
//@property (nonatomic, copy) NSString *value;
@property (nonatomic, strong) CALayer *bottomLine;
@end

@implementation WDGrabOrdersPersonInfoLabelView

- (void)initWithSubView
{
    self.backgroundColor = [UIColor whiteColor];
    CGRect frame = CGRectMake(kRealValue(20), self.height - 1, self.width - kRealValue(20) * 2, 1);
    self.bottomLine = [CALayer drawLine:self frame:frame lineColor:[UIColor colorWithHexString:@"#EEEEEE"]];
    [self initWithTitleLabel];
    
    [self initWithThanImgView];
    
    [self initWithValueLabel];
}

- (void)initWithTitleLabel
{
    if (!_titleLabel) {
        NSString *str = @"交付中心大家";
        float width = [str widthForFont:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium]];
        CGRect frame = CGRectMake(kRealValue(20), (self.height - 30) * 0.5, width, 30);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:14 weight:UIFontWeightRegular] propertiesBlock:^(UILabel * _Nonnull label) {
        }];
    }
}

- (void)initWithThanImgView {
    if (!_thanImgView) {
        UIImage *image = [UIImage imageNamed:@"ic_than_more_99"];
        CGRect frame = CGRectMake(self.width - 20 - image.size.width, (self.height - image.size.height) * 0.5, image.size.width, image.size.height);
        _thanImgView = [[UIImageView alloc] initWithFrame:frame];
        _thanImgView.image = image;
        [self addSubview:_thanImgView];
    }
}

/// 值
- (void)initWithValueLabel {
    if (!_valueLabel) {
        CGRect frame = self.titleLabel.frame;
        frame.origin.x = self.titleLabel.right + 2;
//        frame.size.height = 30;
        frame.size.width = self.thanImgView.left - 8 - self.titleLabel.right - 2;
        _valueLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:14 weight:UIFontWeightRegular] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textAlignment = NSTextAlignmentRight;
            label.text = @"请选择";
            label.textColor = [UIColor colorWithHexString:@"#999999"];
        }];
        
        @weakify(self);
        _valueLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            @strongify(self);
            if (self.viewBlock) {
                self.viewBlock(nil);
            }
        }];
        [_valueLabel addGestureRecognizer:tap];
        
    }
}

- (void)setTitleFont:(UIFont *)titleFont
{
    _titleLabel.font = titleFont;
}

- (void)setTitleColor:(UIColor *)titleColor
{
    _titleLabel.textColor = titleColor;
}

- (void)setValueFont:(UIFont *)valueFont
{
    _valueLabel.font = valueFont;
}

- (void)setValueColor:(UIColor *)valueColor
{
    _valueLabel.textColor = valueColor;
}

- (void)setHiddenBottomLine:(BOOL)hiddenBottomLine
{
    _hiddenBottomLine = hiddenBottomLine;
    _bottomLine.hidden = hiddenBottomLine;
}

- (void)setTextAlignment:(NSTextAlignment)textAlignment {
    _textAlignment = textAlignment;
    _valueLabel.textAlignment = textAlignment;
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    self.titleLabel.text = title;
}

- (void)setPlaceholder:(NSString *)placeholder {
    _placeholder = placeholder;
    self.valueLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    self.valueLabel.text = placeholder;
}

- (void)setValue:(NSString *)value {
    _value = value;
//    if ([objectNull(value) isEqualToString:@""]) {
//        self.valueLabel.textColor = [UIColor colorWithHexString:@"#eeeeee"];
//        self.valueLabel.text = @"请选择";
//    } else {
        self.valueLabel.text = value;
        self.valueLabel.textColor = [UIColor colorWithHexString:@"#333333"];
//    }
}

- (void)setIsRequired:(BOOL)isRequired {
    _isRequired = isRequired;
    if (isRequired) {
        self.titleLabel.attributedText = [EDSUtility attributeTitle:@"* " titleColor:[UIColor colorWithHexString:@"#F24C55"] titleFont:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular] value:self.title valueColor:[UIColor colorWithHexString:@"#333333"] valueFont:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular]];
    } else {
        self.titleLabel.text = self.title;
    }
}


@end
